﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Utility.DBMS;
using System.Data;
using System.Utility.Messaging;
using System.Utility;

namespace GuessLAB
{
    public partial class Activate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Util.LogRequest("Activate Page called.", this.Request, null);
            login.Visible = true;
            string encryptId = Request.QueryString["requestId"].ToString().Replace("+", "").Replace("==", "");
            DataSet set  = DBHelper.GetDataTable("GetResetLink", new object[] { encryptId });

            if (set != null && set.Tables.Count > 0)
            {
                DataTable table = set.Tables[0];
                if (table != null && table.Rows.Count == 1)
                {
                    DateTime expTime = DateTime.Parse(table.Rows[0]["ExpiryTime"].ToString());
                    if (expTime > DateTime.Now)
                    {
                        Logger.LogMessage("Redirecting to UpdatePassword Page", LogLevel.INFO, LogMessageType.WebMessage);
                        Session[encryptId] = table.Rows[0]["UserId"].ToString();
                        Response.Redirect("UpdatePassword.aspx?UId=" + encryptId);
                    }
                    else
                    {
                        lblMessage.Text = MessageFactory.GetMessageByCode("UI1001");
                    }
                }
                else
                {
                    lblMessage.Text = lblMessage.Text = MessageFactory.GetMessageByCode("UI1002");
                    login.Visible = false;
                }
            }
            //DataBAse Call -- Pass Id
            //If Success -- Return UserID and Email
            //Show set New Password and Confirm
            //Update Password

        }
    }
}